package com.ovidiojf.siesec.aluno;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.ovidiojf.siesec.classe.Classe;
import com.ovidiojf.siesec.matriculaEscolar.MatriculaEscolar;

public class AlunoDAOHibernate implements AlunoDAO {

	private Session session;
	
	public Session getSession() {
		return session;
	}
	public void setSession(Session session) {
		this.session = session;
	}

	@Override
	public void salvar(Aluno aluno) {
		this.session.save(aluno);
	}
	@Override
	public void excluir(Aluno aluno) {
		this.session.delete(aluno);
	}
	@Override
	public void alterar(Aluno aluno) {
		this.session.update(aluno);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Aluno> listar() {
		Criteria criteria = this.session.createCriteria(Aluno.class);
		return criteria.list();
	}
	@Override
	public Aluno pesquisarPorId(String id) {
		Criteria criteria = this.session.createCriteria(Aluno.class);
		criteria.add(Restrictions.eq("id", id));
		return (Aluno) criteria.uniqueResult();
	}
	@Override
	public Aluno pesquisarPorRA(String ra) {
		Criteria criteria = this.session.createCriteria(Aluno.class);
		criteria.add(Restrictions.eq("ra", ra));
		return (Aluno) criteria.uniqueResult();
	}
	@Override
	public List<Classe> listClasses(Aluno aluno) {
		return null;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<MatriculaEscolar> listMatriculasEscolares(Aluno aluno) {
		Criteria criteria = this.session.createCriteria(MatriculaEscolar.class);
		criteria.add(Restrictions.eq("aluno", aluno));
		return criteria.list();
	}
}
